﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.Unity;

namespace Skynet.WebSite.Account
{
    public partial class Register : Infrastructure.Web.Views.Page, Skynet.WebAdministracion.Views.Register.IRegisterView
    {

        private Skynet.WebAdministracion.Views.Register.RegisterPresenter _Presenter;

        [Dependency]
        public Skynet.WebAdministracion.Views.Register.RegisterPresenter Presenter
        {
            get { return _Presenter; }
            set
            {
                _Presenter = value;
                this._Presenter.View = this;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.CreateUserWizard1.ContinueDestinationPageUrl = Request.QueryString["ReturnUrl"];
            if (!Page.IsPostBack)
            {
                this.Presenter.OnViewInitialized();
            }
            this.Presenter.OnViewLoaded();
        }

     

        protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            this.Presenter.RegisterCustomer(this.CreateUserWizard1.UserName);
            FormsAuthentication.SetAuthCookie(CreateUserWizard1.UserName, false /* createPersistentCookie */);
            string continueUrl = CreateUserWizard1.ContinueDestinationPageUrl;
            if (String.IsNullOrEmpty(continueUrl))
            {
                continueUrl = "~/";
            }
            Response.Redirect(continueUrl);
        }
    }
}
